<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/24 0024
 * Time: 15:38
 */
//https://blog.csdn.net/weixin_34015860/article/details/85955453
//主进程文件，输出时间（子父进程会sleep的关系，所以可能不会和当前时间相同，差距 2s 以内）
$child_file = "proc_open3_child.php";
$descriptorspec = array(
    0 => array("pipe", "r"),  // 标准输入，子进程从此管道中读取数据
    1 => STDOUT,  // 标准输出，重定向子进程输入到主进程STDOUT
    2 => array("file", "error-output.txt", "a") // 标准错误，写入到一个文件
);
$child_process = proc_open("php {$child_file}", $descriptorspec, $pipes);
//while(1){
//    $time = date("Y-m-d h:i:s");
//    fwrite($pipes[0], "main say {$time}\n");
//    sleep(2);
//}

    $time = date("Y-m-d h:i:s");
    fwrite($pipes[0], "main say {$time}\n");
    fclose($pipes[0]);
    sleep(2);
proc_close($child_process);